<template>
  <div class="table_container">
    <el-table
      :data="turnoverWorkstages"
      ref="tableNode"
      v-loading="isLoading"
      :max-height="tableCascadeHeight"
      border
      stripe
      tooltip-effect="dark">
      <mes-column :key="index" v-for="(column, index) in columns" :column="column"></mes-column>
      <el-table-column
        prop="templateName"
        :resizable="false"
        label="操作"
        width="90"
        show-overflow-tooltip
        fixed="right"
        align="center">
        <template slot-scope="scope">
          <span class="jump_item"
                v-if="authorityJudge(scope.row)"
                :class="{is_disabled: !scope.row.parameterRecordId}"
                @click="showRecord(scope.row)">参数记录</span>
          <span class="jump_item is_disabled"
                v-else>暂无权限</span>
        </template>
      </el-table-column>
    </el-table>
    <see-records ref="SeeRecords"></see-records>
  </div>
</template>

<script>
import workstageColumns from './workstageColumns'
import {SeeRecords} from '../../../../../components/Template'

let storeModule = 'batchProcessTrace'
let productTraceInterFace = 'a/turnoverbatch/turnoverBatch/productTrace'

export default {
  name: 'WorkstageList',
  data() {
    return {
      columns: workstageColumns,
      isLoading: false
    }
  },
  components: {
    SeeRecords
  },
  computed: {
    // 周转批次工序
    turnoverWorkstages() {
      return this.$store.state[storeModule].turnoverDetail.turnoverWorkstages
    },
    userInfo() {
      return this.$store.state.userInfo || {}
    },
  },
  methods: {
    // 获取批次工序
    init(id) {
      this.isLoading = true
      let postData = {
        method: 'post',
        url: productTraceInterFace,
        module: storeModule,
        data: {
          turnoverId: id
        },
        state: 'turnoverDetail',
      }
      this.$store.dispatch('saveData', postData).finally(() => {
        this.isLoading = false
      })
    },
    // 显示参数记录
    showRecord(row) {
      if (row && row.parameterRecordId) this.$refs.SeeRecords.openDialog(row.id)
    },
    // 权限判断
    authorityJudge(row) {
      switch (this.userInfo.secretLevel) {
        case 'ID_PSL_Confidential':
          return true
        case 'ID_PSL_Secret':
          return row.paramRecordSecretLevelId === 'ID_PSL_Public' || row.paramRecordSecretLevelId === 'ID_PSL_Secret'
        case 'ID_PSL_Public':
          return row.paramRecordSecretLevelId === 'ID_PSL_Public'
        default:
          return false
      }
    }
    // ID_PSL_Confidential,ID_PSL_Secret,ID_PSL_Public
  }
}
</script>

<style lang="less" scoped>

</style>
